import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)


export default new Vuex.Store({
  state: {
    
  // 群聊私聊消息 9 为群聊，1 为私聊 用户名私聊时才会存在
  // 私聊的具体成员在chatroom组件中存储，每次新建群组都会获取
  // 全部群组的消息在list组件中
  currentState:{
    toId:null,
    type:'',
    username:'',
    image:'',
    description:'',
    //以下属性都是为了适配群聊
    members:'',
    //群聊属性
    groupChannel:null,
    //私聊/群聊公共
    owner:'',
    //群聊属性
    ownerId:null,
    //私聊/群聊公共
    ownerImage:''
  },
    // 存储token
  Authorization: localStorage.getItem('Authorization') ? localStorage.getItem('Authorization') : '',
  myInfo: {
    userId: null,
    username: "",
    sex: "",
    image: "",
    description: "",
  }
  },
  mutations: {
    commitMyInfo: function(state, info) {
      state.myInfo = info;
      console.log(state.myInfo)
    },
  // 修改token，并将token存入localStorage
  changeLogin (state, user) {
    state.Authorization = user.Authorization;
    localStorage.setItem('Authorization', user.Authorization);
  },
    commitcurrentState: function(state, info){
      state.currentState = info
      console.log("存储的currentState:->",state.currentState)
    }
  },
  actions: {
    chooseAccept: function(state, info) {
     this.commit("commitcurrentState", info)
    },
    saveUserInfo: function(state, info) {
      this.commit("commitMyInfo", info)
    },
  },
  modules: {
  }
})
